﻿@model thailandProject.Models.PROPERTY
@{
    ViewBag.Title = "Add Property";
}

<div id="Wrapper2">
    <div id="content_header">
        <div id="headerimage">
        </div>
        <div id="theheader">@ViewBag.Header</div>
    </div>
    <!-- Left Column begins here -->
    <aside id="sidebar-wrapper">
        <nav class="sidebar">
            <!-- CONTENT GOES HERE -->
            @using (Html.BeginForm("AddProperty", "Admin", FormMethod.Post, new { id = "addForm" }))
            {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>PROPERTY</legend>

        <div class="editor-label">
            <label for="lblAddPropertyName">Name</label>
        </div>
        <div class="editor-field">
            <input type="text" id="propName" name="propName" maxlength="20" />
            <div id="propNameError" style="color:red; visibility:hidden;">Name cannot be empty</div>
        </div>

        <div class="editor-label">
            <label for="lblAddPropertyURL">URL</label>
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.propHyperlink, new { maxlength = 100 })
            @Html.ValidationMessageFor(model => model.propHyperlink)
        </div>

        <div class="editor-label">
            <label for="lblAddPropertyLocation">Location</label>
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.propLocation, new { maxlength = 2000 })
            @Html.ValidationMessageFor(model => model.propLocation)
        </div>

        <div class="editor-label">
           <label for="lblAddPropertyDetails">Details</label>
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.propDetails, new { id = "propDetails" })
            @Html.ValidationMessageFor(model => model.propDetails)
            <div id="charsLeft">&nbsp;</div>
        </div>
  
        
    </fieldset>
            <input type="image" src="../../images/create_button.png" value="Create" class="btnAddEditProperty" />
            <div id="formError" style="color:red; visibility:hidden">Please correct the above errors to continue</div>
                <input type="hidden" id="formcheck" value="false" />
            }

<div>
    @Html.ActionLink("Back to List", "ManageProperties")

</div>
        </nav>
    </aside>
    <!-- Right column begins here -->
    <article id="contents">
        
    </article>
    <!-- Right column ends here -->
</div>
<!-- Div wrapper2 ends here -->

<script>
    $("#addForm").submit(function ()
    {
        if ($("#propName").val() == "") {
            $("#propNameError").attr('style', 'color:red; visibility:visible;');
            $("#formError").attr('style', 'color:red; visibility:visible;');
            $("#propName").focus();
            return false;
        }
        else {
            $("#propNameError").attr('style', 'color:red; visibility:hidden;');
            $("#formError").attr('style', 'color:red; visibility:hidden;');
            if ($("#formcheck").val() == 'false') {
                $("#formcheck").val('true');
                return true;
            }
            else {
                alert('Your action is currently being processed. Please wait');
                return false;
            }
        }
    })

    $("#propDetails").keyup(function () {
        var message = $(this).val();

        if (message.length > 2000) {
            message = message.substr(0, 2000);
            $(this).val(message);
        }

        $("#charsLeft").text(2000 - message.length + " chars left");
    })
</script>